import { axiosInstance } from 'src/boot/axios'
import CommonConfig from 'src/assets/js/config'
// const baseUrlWorkOrder = CommonConfig.planningUrl + '/v1'
const baseUrlTpm = CommonConfig.tpmUrl + '/v1'
// const baseUrlUpms = CommonConfig.upmsUrl + '/v1'
// const baseUrlProcess = CommonConfig.processUrl + '/v1'
// const baseUrlWorkOrder2 = CommonConfig.planningUrl + '/v3'
const baseUrlSchema = CommonConfig.schemaUrl + '/v1'
// const datacenterUrl = CommonConfig.datacenterUrl + '/v1'
// import qs from 'qs'
// const qsConfig = {
//   arrayFormat: 'repeat',
//   skipNulls: true,
//   format: 'RFC3986'
// }

// /v1/maintenance_programs
// 查询设备保养项目列表
export function getMaintenaceProgramsList ({ pageNum, pageSize, maintenanceType, sort }) {
  const newUrl = `${baseUrlTpm}/maintenance_programs`
  const params = {
    pageNum,
    pageSize,
    maintenanceType,
    sort
  }
  return axiosInstance.get(newUrl, { params }).then((res) => {
    return Promise.resolve((res))
  })
}
// POST
// /v1/maintenance_program
// 设备保养项目新增
export function addMaintenacePrograms ({ deviceType, items, maintenanceType, name }) {
  const newUrl = `${baseUrlTpm}/maintenance_program`
  const params = {
    deviceType, items, maintenanceType, name
  }
  return axiosInstance.post(newUrl, params).then((res) => {
    return Promise.resolve((res))
  })
}
// PATCH
// /v1/maintenance_program
// 设备保养项目修改
export function editMaintenacePrograms ({ deviceType, items, maintenanceType, name, id }) {
  const newUrl = `${baseUrlTpm}/maintenance_program`
  const params = {
    deviceType, items, maintenanceType, name, id
  }
  return axiosInstance.patch(newUrl, params).then((res) => {
    return Promise.resolve((res))
  })
}
// GET
// /v1/maintenance_program/{id}
// 根据id查询设备保养项目
export function getMaintenaceProgramsById (id) {
  const newUrl = `${baseUrlTpm}/maintenance_program/${id}`
  return axiosInstance.get(newUrl).then((res) => {
    return Promise.resolve((res))
  })
}
// DELETE
// /v1/maintenance_program/{id}
// 根据id删除设备保养项目
export function deleteMaintenaceProgramsById (id) {
  const newUrl = `${baseUrlTpm}/maintenance_program/${id}`
  return axiosInstance.delete(newUrl).then((res) => {
    return Promise.resolve((res))
  })
}
// maintain_item_content
// 获取保养项目的下拉选项目内容
export function getMaintainContent (disable, dicGroupCode = 'maintain_item_content') {
  const newUrl = baseUrlSchema + '/dict_by_gcode'
  let params = {
    dicGroupCode,
    disable
  }
  return axiosInstance.get(newUrl, { params }).then((res) => {
    const ret = res.data
    return Promise.resolve(ret)
  })
}
